<?php


namespace app\controllers;

use app\models\Admin;
use Yii;
use yii\web\Controller;
use yii\filters\AccessControl;
class PowerController extends Controller
{
    public function behaviors()
    {
        $rules = [];
        if (empty($_COOKIE['admin'])) {
            $rules[] = [
                'allow' => true,
                'controllers' => Yii::$app->params['without_login_controllers'],
                'roles' => ['?'],
            ];
        }else{
                $rules[] = [
                    'allow' => true,
                    'controllers' => ['admin'],
                    'roles' => ['?'],
                ];
        }
        $rules[] = [
            'allow' => true,
            'roles' => ['@'],
        ];
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => $rules,
                'denyCallback' => function ($rule, $action) {
            if (empty($_COOKIE['admin'])){
                Yii::$app->user->loginRequired();
                return false;
            }
                }
            ],
        ];
    }
}